package com.ccq;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ccq.domain.Result;
import com.ccq.util.ResultUtil;



@ControllerAdvice
public class GlobalExceptionHandler  extends RuntimeException{
	/**
	 * 统一异常处理
	 */
	private static final long serialVersionUID = 1L;
	public  static final Log log=LogFactory.getLog(GlobalExceptionHandler.class);
	@SuppressWarnings("unchecked")
	@ResponseBody
	@ExceptionHandler(value=Exception.class)
	public <T> Result<T> catchException(Exception e){
		if(e instanceof MyException){
			log.error("Exception={}"+e);
			return (Result<T>) ResultUtil.erro(ResultEum.Erro);
		}else {
			log.error("Exception={}"+e);
			return (Result<T>) ResultUtil.unKnow(ResultEum.UnknownError);
		}
	}
}
